<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="../../component/pear/css/pear.css" />
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="warehouseRecord-table" lay-filter="warehouseRecord-table"></table>
			</div>
		</div>

	<script type="text/html" id="warehouseRecord-toolbar">
		<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
			<i class="layui-icon layui-icon-add-1"></i>
			新增
		</button>
		<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
			<i class="layui-icon layui-icon-delete"></i>
			删除
		</button>
	</script>

	<script type="text/html" id="user-bar">
		<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
        <button class="pear-btn pear-btn-sm" id="more_{{d.userId}}"><i class="layui-icon layui-icon-triangle-d"></i></button>
	</script>


	<script type="text/html" id="in-and-out-type">
		{{#if (d.inAndOutType == 1) { }}
		<span>出库</span>
		{{# }else if(d.inAndOutType == 2){ }}
		<span>入库</span>
		{{# } }}
	</script>


	<script type="text/html" id="warehouseRecord-createTime">
		{{layui.util.toDateString(d.addTime, 'yyyy-MM-dd HH:mm:ss')}}
	</script>

	<script type="text/html" id="warehouseRecord-updateTime">
		{{layui.util.toDateString(d.lastUpdateTime, 'yyyy-MM-dd HH:mm:ss')}}
	</script>

	<div style="display: none;">
		<div class="layer-top">
			<br />
			<h3>上侧弹层内容...</h3>
		</div>
	</div>

		<script src="../../component/layui/layui.js"></script>
		<script src="../../component/pear/pear.js"></script>
		<script>
			layui.use(['table', 'form', 'jquery', 'drawer', 'dropdown'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let drawer = layui.drawer;
				let dropdown = layui.dropdown;

				let MODULE_PATH = "/system/user/";

				let cols = [
					[{
							type: 'checkbox'
						},
						{
							title: '设备编号',
							field: 'equipmentId',
							align: 'center',
							width: 100
						},
						{
							title: '设备名称',
							field: 'equipmentName',
							align: 'center',
							width: 100
						},
						{
							title: '出入库类型',
							field: 'inAndOutType',
							align: 'center',
							templet: '#in-and-out-type'
						},
						{
							title: '检查人姓名',
							field: 'checkUserName',
							align: 'center'
						},
						{
							title: '数据添加时间',
							field: 'addTime',
							align: 'center',
							templet: '#warehouseRecord-createTime'
						},
						{
							title: '数据更新时间',
							field: 'lastUpdateTime',
							align: 'center',
							templet: '#warehouseRecord-updateTime'
						}
					]
				]

				table.render({
					elem: '#warehouseRecord-table',
					url: '/warehouseRecord/queryWarehouseRecordList',
					page: true,
					cols: cols,
					skin: 'line',
					toolbar: '#warehouseRecord-toolbar',
					defaultToolbar: [{
						layEvent: 'refresh',
						icon: 'layui-icon-refresh',
					}, 'filter', 'print', 'exports'],
					done: function(res, curr, count) {
                             //  for (var i = 0; i < res.data.length; i++) {
                             //     dropdown.render({
                             //         elem: '#more_' + res.data[i].userId
                             //     , data: [{
                             //             title: 'menu item11'
                             //             , id: 100
                             //         }, {
                             //             title: 'menu item22'
                             //             , id: 101
                             //         }, {
                             //             title: 'menu item33'
                             //             , id: 102
                             //             }]
                             //         , id: '#more_' + res.data[i].userId
                             //         , click: function (obj) {
                             //             layer.tips('点击了：' + obj.title, this.elem, { tips: [1, '#5FB878'] })
                             //         }
                             //     });
					         // }
                        }
				});

				// table.on('tool(user-table)', function(obj) {
				// 	if (obj.event === 'remove') {
				// 		window.remove(obj);
				// 	} else if (obj.event === 'edit') {
				// 		window.edit(obj);
				// 	}
				// });

				table.on('toolbar(warehouseRecord-table)', function(obj) {
					if (obj.event === 'add') {
						window.add();
					} else if (obj.event === 'refresh') {
						window.refresh();
					} else if (obj.event === 'batchRemove') {
						window.batchRemove(obj);
					}
				});

				form.on('submit(warehouseRecord-query)', function(data) {
					table.reload('warehouseRecord-table', {
						where: data.field
					})
					return false;
				});

				// form.on('switch(user-enable)', function(obj) {
				// 	layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
				// });

				window.add = function() {
					layer.open({
						type: 2,
						title: '新增出入库记录',
						shade: 0.1,
						area: ['500px', '400px'],
						content: '/warehouseRecord/infoTable/add'
					});
				}

				// window.edit = function(obj) {
				// 	layer.msg("修改");
				// }

				// window.remove = function(obj) {
				// 	layer.confirm('确定要删除该用户', {
				// 		icon: 3,
				// 		title: '提示'
				// 	}, function(index) {
				// 		layer.close(index);
				// 		let loading = layer.load();
				// 		$.ajax({
				// 			url: MODULE_PATH + "remove/" + obj.data['userId'],
				// 			dataType: 'json',
				// 			type: 'delete',
				// 			success: function(result) {
				// 				layer.close(loading);
				// 				if (result.success) {
				// 					layer.msg(result.msg, {
				// 						icon: 1,
				// 						time: 1000
				// 					}, function() {
				// 						obj.del();
				// 					});
				// 				} else {
				// 					layer.msg(result.msg, {
				// 						icon: 2,
				// 						time: 1000
				// 					});
				// 				}
				// 			}
				// 		})
				// 	});
				// }

				window.batchRemove = function(obj) {
					let data = table.checkStatus(obj.config.id).data;
					if (data.length === 0) {
						layer.msg("未选中数据", {
							icon: 3,
							time: 1000
						});
						return false;
					}
					let idArray = data.map(e => e.id);
					layer.confirm('确定要删除这些信息么', {
						icon: 3,
						title: '提示'
					}, function(index) {
						layer.close(index);
						let loading = layer.load();
						$.ajax({
							url: '/warehouseRecord/deleteWarehouseRecord',
							data: JSON.stringify(idArray),
							contentType: 'application/json',
							type: 'post',
							success: function(result) {
								layer.close(loading);
								if (result.code === 0) {
									layer.msg(result.msg, {
										icon: 1,
										time: 1000
									}, function() {
										table.reload('warehouseRecord-table');
									});
								} else {
									layer.msg(result.msg, {
										icon: 2,
										time: 1000
									});
								}
							}
						})
					});
				}

				window.refresh = function(param) {
					table.reload('user-table');
				}
			})
		</script>
	</body>
</html>
